use Test::More 'no_plan';

use lib "../lib/cpp", "../lib/ioc", "../lib/toolkit", '../lib/message';

use TinyMessage;
use Signature;

use CHeaderParser;
use CProject;
use CConstructorMatcher;
use CCodeGenerator;
use FindBin;

use IProject;
use IModule;
use IProvider;
use ICreator;

use TestHelper;

my $source = "$FindBin::Bin/cpp/test-creator-1/";
my $out = $source . "generated";

my $iproject = new IProject();
$iproject->load(new CProject($source));

my @modules = @{ $iproject->modules() };

my $module = $iproject->module('Nested::AppModule3');
ok($module);

my $moduleClasses = $module->moduleClasses();

is($moduleClasses->keys(), 1);

ok($moduleClasses->exists('ServiceV2::GreetingService'));

my $creator = undef;

{
	$provider = $module->class_provider('Log::Logger');
	ok($provider);
	is_deeply($provider, "getModule2()->getLogger");
}

{
	$provider = $module->class_provider('Service::GreetingService');
	ok($provider);
	is_deeply($provider, "getModule2()->getGreetingService");
}

{
	$creator = $module->class_creator('ServiceV2::GreetingService');
	ok($creator);
	is(signature($creator->class()->to_carg('*')), 'ServiceV2::GreetingService*');
	is(stringfy($creator->class()), 'ServiceV2__GreetingService');
	is($creator->ctor()->count(), 2);
	is(signature($creator->ctor()->arg(0)), 'Log::Logger*');
	is(signature($creator->ctor()->arg(1)), 'Service::GreetingService*');
}


is_deeply($module->includes_rel($out), [
	'../source/AppModule2.h', 
	'../source/AppModule3.h', 
	'../source/GreetingService.h', 
	'../source/GreetingServiceV2.h', 
	'../source/Logger.h']);
	
is_deeply($module->providers(), [
	new IProvider( 
		class_sig('ServiceV2::GreetingService', []),  
		class_sig('ServiceV2::GreetingService', []), 
		'getGreetingService', 's',
		class_sig('SINGLETON< ServiceV2::GreetingService >', []) )]);
		
CCodeGenerator::generate($module, $out);
isSame($out . "/Nested__AppModule3.cpp", $out . "/Nested__AppModule3.real");